﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.BLL;
using KPIS.GERP.GIMS.IBLL;
using KPIS.GERP.GIMS.MODEL;
using System.Data;
using System.IO;

namespace KPIS.GERP.GIMS.APP.APP_UI.UserControl
{
    public partial class TIP_Pre_Purchase_Request_Confirm : System.Web.UI.UserControl
    {
        Common.Main cn = new Common.Main();
        public CallBackHandle RefreshParentDisplay;
        public CallBackHandleAlert Alert;
        public CallBackHandleReturnInt GetPprSeq;
        List<string[]> ApproveControlName = new List<string[]>();
        List<string> DelButtonApproveName = new List<string>();
        List<string[]> KnowControlName = new List<string[]>();
        List<string> DelButtonKnowName = new List<string>();
        IBLLHrmEmployee bllEmployee = new HrmEmployeeBLL();
        IBLLPrePurchaseRequest bll = new PrePurchaseRequestBLL();
        EssMessageSendBLL sendBLL = new EssMessageSendBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            int loop = 0;
            if (ViewState["Loop"] != null)
            {
                loop = Convert.ToInt32(ViewState["Loop"]);
            }
            if (loop == 0)
            {
                btnCreateApprove_Click(null, null);
                btnCreateKnow_Click(null, null);
            }
            else
            {
                this.ApproveControlName = (List<string[]>)Session["ApproveControlName"];
                this.DelButtonApproveName = (List<string>)Session["DelButtonApproveName"];
                CreateApproveEmpControls(ref this.ApproveControlName, ref this.DelButtonApproveName);

                this.KnowControlName = (List<string[]>)Session["KnowControlName"];
                this.DelButtonKnowName = (List<string>)Session["DelButtonKnowName"];
                CreateKnowEmpControls(ref this.KnowControlName, ref this.DelButtonKnowName);
            }
        }

        protected void btnCreateApprove_Click(object sender, EventArgs e)
        {
            int TmpNumOfName = ApproveControlName.Count;
            foreach (string[] cur in this.ApproveControlName)
            {
                if (cur[0] == "cbApproveEmployee" + TmpNumOfName.ToString())
                {
                    TmpNumOfName++;
                }
            }
            string[] ControlName = { "cbApproveEmployee" + TmpNumOfName.ToString(), "" };
            this.ApproveControlName.Add(ControlName);
            this.DelButtonApproveName.Add("delApproveEmployee" + TmpNumOfName.ToString());
            Session["ApproveControlName"] = this.ApproveControlName;
            Session["DelButtonApproveName"] = this.DelButtonApproveName;
            CreateApproveEmpControl(ref this.ApproveControlName, ref this.DelButtonApproveName);
            ViewState["Loop"] = 1;
        }

        protected void btnCreateKnow_Click(object sender, EventArgs e)
        {
            int TmpNumOfName = KnowControlName.Count;
            foreach (string[] cur in this.KnowControlName)
            {
                if (cur[0] == "cbKnowEmployee" + TmpNumOfName.ToString())
                {
                    TmpNumOfName++;
                }
            }
            string[] ControlName = { "cbKnowEmployee" + TmpNumOfName.ToString(), "" };
            this.KnowControlName.Add(ControlName);
            this.DelButtonKnowName.Add("delKnowEmployee" + TmpNumOfName.ToString());
            Session["KnowControlName"] = this.KnowControlName;
            Session["DelButtonKnowName"] = this.DelButtonKnowName;
            CreateKnowEmpControl(ref this.KnowControlName, ref this.DelButtonKnowName);
            ViewState["Loop"] = 1;
        }

        protected void btnDelApprove_Click(object sender, ImageClickEventArgs e)
        {
            Table TmpTB = (Table)RadPanelBar.FindItemByValue("BarH1").FindControl("tbApprove");
            ImageButton TmpIB = (ImageButton)sender;
            for (int i = 0; i < DelButtonApproveName.Count; i++)
            {
                if (DelButtonApproveName[i] == TmpIB.ID)
                {
                    TmpTB.Rows.RemoveAt(Convert.ToInt32(ApproveControlName[i][1]));
                    ApproveControlName.RemoveAt(i);
                    DelButtonApproveName.RemoveAt(i);
                    break;
                }
            }

            for (int i = 0; i < TmpTB.Rows.Count; i++)
            {
                foreach (Control child in TmpTB.Rows[i].Cells[0].Controls)
                {
                    if (child.GetType().ToString().Equals("System.Web.UI.WebControls.Label")
                              && child.ID.IndexOf("lbl_") == 0)
                    {
                        Label lbl = (Label)child;
                        lbl.Text = "ลำดับที่ " + i + " :";
                    }
                }
            }
        }

        protected void btnDelKnow_Click(object sender, ImageClickEventArgs e)
        {
            Table TmpTB = (Table)RadPanelBar.FindItemByValue("BarH2").FindControl("tbKnow");
            ImageButton TmpIB = (ImageButton)sender;
            for (int i = 0; i < DelButtonKnowName.Count; i++)
            {
                if (DelButtonKnowName[i] == TmpIB.ID)
                {
                    TmpTB.Rows.RemoveAt(Convert.ToInt32(KnowControlName[i][1]));
                    KnowControlName.RemoveAt(i);
                    DelButtonKnowName.RemoveAt(i);
                    break;
                }
            }

            for (int i = 0; i < TmpTB.Rows.Count; i++)
            {
                foreach (Control child in TmpTB.Rows[i].Cells[0].Controls)
                {
                    if (child.GetType().ToString().Equals("System.Web.UI.WebControls.Label")
                              && child.ID.IndexOf("lbl_") == 0)
                    {
                        Label lbl = (Label)child;
                        lbl.Text = "บุคคลที่ " + i + " :";
                    }
                }
            }
        }

        protected void CreateApproveEmpControls(ref List<string[]> ControlName, ref List<string> DelControlName)
        {
            if (ControlName.Count > 0)
            {
                for (int i = 0; i < ControlName.Count; ++i)
                {
                    TableRow tr = new TableRow();

                    TableCell tc1 = new TableCell();
                    TableCell tc2 = new TableCell();
                    TableCell tc3 = new TableCell();

                    Label lbl = new Label();
                    lbl.ID = "lbl_" + i.ToString();
                    lbl.Text = "ลำดับที่ " + (i + 1).ToString() + " : ";

                    RadComboBox TmpCB = new RadComboBox();

                    TmpCB.ID = ControlName[i][0].ToString();
                    TmpCB.EnableLoadOnDemand = true;
                    TmpCB.EmptyMessage = ".. พิมพ์ที่นี่เพื่อช่วยค้นหา .. ";
                    TmpCB.AllowCustomText = true;
                    TmpCB.Height = 230;
                    TmpCB.HighlightTemplatedItems = true;
                    TmpCB.MarkFirstMatch = false;
                    TmpCB.ShowDropDownOnTextboxClick = true;
                    TmpCB.ShowMoreResultsBox = true;
                    TmpCB.EnableVirtualScrolling = true;
                    TmpCB.Width = 475;
                    TmpCB.Style.Add("z-index", "8001");
                    HT h = new HT();
                    TmpCB.HeaderTemplate = h;
                    T t = new T();
                    TmpCB.ItemTemplate = t;
                    TmpCB.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(Combobox_ItemsRequested);
                    TmpCB.OnClientTextChange = "onTextChangeGeneral";

                    ImageButton del = new ImageButton();
                    del.ID = DelControlName[i];
                    del.ImageUrl = "../Image/Grid/Cancel.gif";
                    del.Click += new ImageClickEventHandler(this.btnDelApprove_Click);

                    tc1.Controls.Add(lbl);
                    tc2.Controls.Add(TmpCB);
                    tc3.Controls.Add(del);

                    tr.Cells.AddAt(0, tc1);
                    tr.Cells.AddAt(1, tc2);
                    tr.Cells.AddAt(2, tc3);

                    Table TmpTB = (Table)RadPanelBar.FindItemByValue("BarH1").FindControl("tbApprove");

                    TmpTB.Rows.Add(tr);
                    ControlName[i][1] = (TmpTB.Rows.Count - 1).ToString();
                }
            }
        }

        protected void CreateApproveEmpControl(ref List<string[]> ControlName, ref List<string> DelControlName)
        {
            TableRow tr = new TableRow();

            TableCell tc1 = new TableCell();
            TableCell tc2 = new TableCell();
            TableCell tc3 = new TableCell();

            Label lbl = new Label();
            lbl.ID = "lbl_" + (ControlName.Count).ToString();
            lbl.Text = "ลำดับที่ " + (ControlName.Count).ToString() + " : ";

            RadComboBox TmpCB = new RadComboBox();

            TmpCB.ID = ControlName[ControlName.Count - 1][0].ToString();
            TmpCB.EnableLoadOnDemand = true;
            TmpCB.EmptyMessage = ".. พิมพ์ที่นี่เพื่อช่วยค้นหา .. ";
            TmpCB.AllowCustomText = true;
            TmpCB.Height = 230;
            TmpCB.HighlightTemplatedItems = true;
            TmpCB.MarkFirstMatch = false;
            TmpCB.ShowDropDownOnTextboxClick = true;
            TmpCB.ShowMoreResultsBox = true;
            TmpCB.EnableVirtualScrolling = true;
            TmpCB.Width = 475;
            TmpCB.Style.Add("z-index", "8001");
            HT h = new HT();
            TmpCB.HeaderTemplate = h;
            T t = new T();
            TmpCB.ItemTemplate = t;
            TmpCB.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(Combobox_ItemsRequested);
            TmpCB.OnClientTextChange = "onTextChangeGeneral";

            ImageButton del = new ImageButton();
            del.ID = DelControlName[DelControlName.Count - 1];
            del.ImageUrl = "../Image/Grid/Cancel.gif";
            del.Click += new ImageClickEventHandler(this.btnDelApprove_Click);

            tc1.Controls.Add(lbl);
            tc2.Controls.Add(TmpCB);
            tc3.Controls.Add(del);

            tr.Cells.AddAt(0, tc1);
            tr.Cells.AddAt(1, tc2);
            tr.Cells.AddAt(2, tc3);

            Table TmpTB = (Table)RadPanelBar.FindItemByValue("BarH1").FindControl("tbApprove");

            TmpTB.Rows.Add(tr);
            ControlName[ControlName.Count - 1][1] = (TmpTB.Rows.Count - 1).ToString();
        }

        protected void CreateKnowEmpControls(ref List<string[]> ControlName, ref List<string> DelControlName)
        {
            if (ControlName.Count > 0)
            {
                for (int i = 0; i < ControlName.Count; ++i)
                {
                    TableRow tr = new TableRow();

                    TableCell tc1 = new TableCell();
                    TableCell tc2 = new TableCell();
                    TableCell tc3 = new TableCell();

                    Label lbl = new Label();
                    lbl.ID = "lbl_" + i.ToString();
                    lbl.Text = "บุคคลที่ " + (i + 1).ToString() + " : ";

                    RadComboBox TmpCB = new RadComboBox();

                    TmpCB.ID = ControlName[i][0].ToString();
                    TmpCB.EnableLoadOnDemand = true;
                    TmpCB.EmptyMessage = ".. พิมพ์ที่นี่เพื่อช่วยค้นหา .. ";
                    TmpCB.AllowCustomText = true;
                    TmpCB.Height = 230;
                    TmpCB.HighlightTemplatedItems = true;
                    TmpCB.MarkFirstMatch = false;
                    TmpCB.ShowDropDownOnTextboxClick = true;
                    TmpCB.ShowMoreResultsBox = true;
                    TmpCB.EnableVirtualScrolling = true;
                    TmpCB.Width = 475;
                    TmpCB.Style.Add("z-index", "8001");
                    HT h = new HT();
                    TmpCB.HeaderTemplate = h;
                    T t = new T();
                    TmpCB.ItemTemplate = t;
                    TmpCB.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(Combobox_ItemsRequested);
                    TmpCB.OnClientTextChange = "onTextChangeGeneral";

                    ImageButton del = new ImageButton();
                    del.ID = DelControlName[i];
                    del.ImageUrl = "../Image/Grid/Cancel.gif";
                    del.Click += new ImageClickEventHandler(this.btnDelKnow_Click);

                    tc1.Controls.Add(lbl);
                    tc2.Controls.Add(TmpCB);
                    tc3.Controls.Add(del);

                    tr.Cells.AddAt(0, tc1);
                    tr.Cells.AddAt(1, tc2);
                    tr.Cells.AddAt(2, tc3);

                    Table TmpTB = (Table)RadPanelBar.FindItemByValue("BarH2").FindControl("tbKnow");

                    TmpTB.Rows.Add(tr);
                    ControlName[i][1] = (TmpTB.Rows.Count - 1).ToString();
                }
            }
        }

        protected void CreateKnowEmpControl(ref List<string[]> ControlName, ref List<string> DelControlName)
        {
            TableRow tr = new TableRow();

            TableCell tc1 = new TableCell();
            TableCell tc2 = new TableCell();
            TableCell tc3 = new TableCell();

            Label lbl = new Label();
            lbl.ID = "lbl_" + (ControlName.Count).ToString();
            lbl.Text = "บุคคลที่ " + (ControlName.Count).ToString() + " : ";

            RadComboBox TmpCB = new RadComboBox();

            TmpCB.ID = ControlName[ControlName.Count - 1][0].ToString();
            TmpCB.EnableLoadOnDemand = true;
            TmpCB.EmptyMessage = ".. พิมพ์ที่นี่เพื่อช่วยค้นหา .. ";
            TmpCB.AllowCustomText = true;
            TmpCB.Height = 230;
            TmpCB.HighlightTemplatedItems = true;
            TmpCB.MarkFirstMatch = false;
            TmpCB.ShowDropDownOnTextboxClick = true;
            TmpCB.ShowMoreResultsBox = true;
            TmpCB.EnableVirtualScrolling = true;
            TmpCB.Width = 475;
            TmpCB.Style.Add("z-index", "8001");
            HT h = new HT();
            TmpCB.HeaderTemplate = h;
            T t = new T();
            TmpCB.ItemTemplate = t;
            TmpCB.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(Combobox_ItemsRequested);
            TmpCB.OnClientTextChange = "onTextChangeGeneral";

            ImageButton del = new ImageButton();
            del.ID = DelControlName[DelControlName.Count - 1];
            del.ImageUrl = "../Image/Grid/Cancel.gif";
            del.Click += new ImageClickEventHandler(this.btnDelKnow_Click);

            tc1.Controls.Add(lbl);
            tc2.Controls.Add(TmpCB);
            tc3.Controls.Add(del);

            tr.Cells.AddAt(0, tc1);
            tr.Cells.AddAt(1, tc2);
            tr.Cells.AddAt(2, tc3);

            Table TmpTB = (Table)RadPanelBar.FindItemByValue("BarH2").FindControl("tbKnow");

            TmpTB.Rows.Add(tr);
            ControlName[ControlName.Count - 1][1] = (TmpTB.Rows.Count - 1).ToString();
        }

        protected void Combobox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            IList<HrmEmployeeInfo> infoList = bllEmployee.GetHrmEmployee(e.Text);
            int itemOffset = e.NumberOfItems;
            int endOffset = Math.Min(itemOffset + 10, infoList.Count);
            e.EndOfItems = (endOffset == infoList.Count);
            int j = 0;
            for (int i = itemOffset; i < endOffset; i++)
            {
                RadComboBox cbAppEmp = (RadComboBox)sender;
                cbAppEmp.Items.Add(new RadComboBoxItem(infoList[i].Name, infoList[i].Seq.ToString()));
                TableRow tr = new TableRow();
                TableCell tdJobSite = new TableCell();
                Label lblJobSite = new Label();
                lblJobSite.Text = infoList[i].InfoJobSite.Name;
                tdJobSite.Width = Unit.Pixel(200);
                tdJobSite.Controls.Add(lblJobSite);
                tr.Cells.Add(tdJobSite);
                TableCell tdName = new TableCell();
                Label lblName = new Label();
                lblName.Text = infoList[i].Name;
                tdName.Width = Unit.Pixel(150);
                tdName.Controls.Add(lblName);
                tr.Cells.Add(tdName);
                TableCell tdPosition = new TableCell();
                Label lblPosition = new Label();
                lblPosition.Text = infoList[i].InfoPosition.Name;
                tdPosition.Width = Unit.Pixel(150);
                tdPosition.Controls.Add(lblPosition);
                tr.Cells.Add(tdPosition);
                TableCell tdClass = new TableCell();
                Label lblClass = new Label();
                lblClass.Text = infoList[i].InfoClass.Name;
                tdClass.Width = Unit.Pixel(190);
                tdClass.Controls.Add(lblClass);
                tr.Cells.Add(tdClass);
                ((Table)cbAppEmp.Items[j].FindControl("tableInternalName")).Controls.Add(tr);
                j++;
            }

            e.Message = GetStatusMessage(endOffset, infoList.Count);
        }

        private static string GetStatusMessage(int offset, int total)
        {
            if (total <= 0)
                return "ไม่มีข้อมูล";

            return String.Format("รายการที่ <b>1</b>-<b>{0}</b> จากทั้งหมด <b>{1}</b> รายการ", offset, total);
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            IBLLPrePurchaseRequest bllPrr = new PrePurchaseRequestBLL();

            IList<PrePurchaseRequestItemInfo> infoPpritem = (IList<PrePurchaseRequestItemInfo>)Session["infoPpritem"];

            if (ApproveControlName.Count == 0)
            {
                //Session["Alert"] = "กรุณาเพิ่มข้อมูลผู้อนุมัติ";
                //Alert();
                //return;
            }

            int cbSelectedValue = 0;
            for (int i = 0; i < ApproveControlName.Count; ++i)
            {
                RadComboBox TmpCB = (RadComboBox)RadPanelBar.FindItemByValue("BarH1").FindControl(this.ApproveControlName[i][0]);
                if (TmpCB.SelectedValue.ToString() != "")
                {
                    cbSelectedValue++;
                    break;
                }
            }

            if (cbSelectedValue == 0)
            {
                //Session["Alert"] = "กรุณาเลือกผู้อนุมัติอย่างน้อย 1 คน";
                //Alert();
                //return;
            }

            PrePurchaseRequestInfo info1 = new PrePurchaseRequestInfo();
            info1.InfoEmployeeConfirmed = new HrmEmployeeInfo();
            info1.Seq = GetPprSeq();
            info1.InfoEmployeeConfirmed.Seq = Convert.ToInt32(Session["EmpSeq"]);
            info1.DateConfirmed = DateTime.Today;
            bll.Confirm(info1, null);

            try
            {
                List<PrePurchaseRequestRouteInfo> ListInfoPprRoute = new List<PrePurchaseRequestRouteInfo>();
                int Seq = GetPprSeq();
                PrePurchaseRequestInfo info = bll.GetPrePurchaseRequest(Convert.ToInt32(Seq));
                HrmEmployeeInfo infoEmp = new HrmEmployeeInfo();
                infoEmp.Seq = Int32.Parse(Session["EmpSeq"].ToString());
                info.InfoEmployeeConfirmed = infoEmp;
                info.DateConfirmed = DateTime.Now;

                int No = 1;
                for (int i = 0; i < ApproveControlName.Count; ++i)
                {
                    RadComboBox TmpCB = (RadComboBox)RadPanelBar.FindItemByValue("BarH1").FindControl(this.ApproveControlName[i][0]);
                    if (TmpCB.SelectedValue.ToString() != "")
                    {
                        PrePurchaseRequestRouteInfo InfoPprRoute = new PrePurchaseRequestRouteInfo();
                        PrePurchaseRequestInfo InfoPpr = new PrePurchaseRequestInfo();
                        HrmEmployeeInfo infoFromEmp = new HrmEmployeeInfo();
                        HrmEmployeeInfo infoToEmp = new HrmEmployeeInfo();
                        RecordInfo InfoRecord = new RecordInfo();
                        SysRouteStatusInfo InfoRouteStstus = new SysRouteStatusInfo();

                        InfoPprRoute.InfoPrePurchaseRequest = info;

                        infoFromEmp.Seq = Int32.Parse(Session["EmpSeq"].ToString());
                        InfoPprRoute.InfoFromEmp = infoFromEmp;

                        infoToEmp.Seq = Convert.ToInt32(TmpCB.SelectedValue.ToString());
                        InfoPprRoute.InfoToEmp = infoToEmp;

                        InfoPprRoute.Order = i + 1;
                        InfoPprRoute.Type = "APPROVE";

                        InfoPprRoute.Active = "Y";

                        InfoRouteStstus.Status = "W";
                        InfoPprRoute.InfoRouteStatus = InfoRouteStstus;

                        InfoRecord.Created_by = cn.UserID;
                        InfoRecord.Created_when = DateTime.Now;
                        InfoPprRoute.InfoRecord = InfoRecord;

                        ListInfoPprRoute.Add(InfoPprRoute);
                        No++;
                    }
                }

                No = 1;
                for (int i = 0; i < KnowControlName.Count; ++i)
                {
                    RadComboBox TmpCB = (RadComboBox)RadPanelBar.FindItemByValue("BarH2").FindControl(this.KnowControlName[i][0]);
                    if (TmpCB.SelectedValue.ToString() != "")
                    {
                        PrePurchaseRequestRouteInfo InfoPprRoute = new PrePurchaseRequestRouteInfo();
                        PrePurchaseRequestInfo InfoPpr = new PrePurchaseRequestInfo();
                        HrmEmployeeInfo infoFromEmp = new HrmEmployeeInfo();
                        HrmEmployeeInfo infoToEmp = new HrmEmployeeInfo();
                        RecordInfo InfoRecord = new RecordInfo();
                        SysRouteStatusInfo InfoRouteStstus = new SysRouteStatusInfo();

                        InfoPprRoute.InfoPrePurchaseRequest = info;

                        infoFromEmp.Seq = Int32.Parse(Session["EmpSeq"].ToString());
                        InfoPprRoute.InfoFromEmp = infoFromEmp;

                        infoToEmp.Seq = Convert.ToInt32(TmpCB.SelectedValue.ToString());
                        InfoPprRoute.InfoToEmp = infoToEmp;

                        InfoPprRoute.Order = i + 1;
                        InfoPprRoute.Type = "INFORM";

                        InfoPprRoute.Active = "Y";

                        InfoRouteStstus.Status = "W";
                        InfoPprRoute.InfoRouteStatus = InfoRouteStstus;

                        InfoRecord.Created_by = cn.UserID;
                        InfoRecord.Created_when = DateTime.Now;
                        InfoPprRoute.InfoRecord = InfoRecord;

                        ListInfoPprRoute.Add(InfoPprRoute);
                        No++;
                    }
                }
                //SendApprove("", ListInfoPprRoute[0].InfoToEmp.Seq);

                //bllPrr.Confirm(info, ListInfoPprRoute);

                Session["Alert"] = SystemInfo._ConfirmComplete;
                RefreshParentDisplay();
                Alert();
            }
            catch
            {
                Session["Alert"] = SystemInfo._InsertError;
                Alert();
                return;
            }
        }
        protected void SendApprove(string strText, Nullable<int> ApprovedSeq)
        {
            EssMessageSendInfo info = new EssMessageSendInfo();

            info.send_date = DateTime.Today;
            info.ref_seq = string.IsNullOrEmpty(GetPprSeq().ToString()) ? (int?)null : GetPprSeq();// main.ConvertNullInt(lblBgmProjOperSeq.Text);
            info.ref_type = "icm_pre_purchase_request";
            info.ref_no = "";
            info.send_text = "แจ้งความประสงค์ขอซื้อ/จ้าง : " + strText;
            info.from_emp_seq = Int32.Parse(Session["EmpSeq"].ToString());
            info.to_emp_seq = ApprovedSeq; // main.ConvertNullInt(lblApproverEmpSeq.Text);
            //info.from_send_seq = main.ConvertNullInt(lblSendSeq.Text);
            info.remarks = null;
            info.message_status = "0";
            info.approve_path_seq = GetApprovedPath() > 0 ? GetApprovedPath() : (int?)null;
            info.created_by = Int32.Parse(Session["EmpSeq"].ToString());
            info.created_when = DateTime.Now;
            sendBLL.Insert(info);
        }
        protected int GetApprovedPath()
        {
            string strNextSeqNo = sendBLL.GetNextStepNo("5"); // (lblApprovePathSeq.Text);

            DataTable dtb = sendBLL.GetCurrentApprover(Session["EmpSeq"].ToString(), "icm_pre_purchase_request"
                    , Convert.ToInt32(strNextSeqNo));
            int ApprovedPath = 0;

            if (dtb != null)
            {
                if (dtb.Rows.Count > 0)
                {
                    ApprovedPath = Int32.Parse(dtb.Rows[0]["approve_path_seq"].ToString());
                    //LoadEmpInfo(dtb.Rows[0]["emp_seq"].ToString());
                }
            }
            return ApprovedPath;
        }
    }
}